package com.front.managementfront.dictionary.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.front.managementfront.dictionary.entity.HktsDictionaryList;
import com.front.managementfront.dictionary.service.IHktsDictionaryListService;
import com.front.managementfront.dictionary.vo.DictionaryParamterVo;
import com.front.managementfront.dictionary.vo.DictionaryVo;
import com.front.managementfront.utils.CustomPageUtils;
import com.hkts.management.common.utils.CustomPage;
import com.hkts.management.common.utils.Result;
import com.hkts.management.common.utils.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yck
 * @since 2021-05-09
 */
@RestController
@RequestMapping("/front/hktsDictionaryList")
@Api(tags = "字典接口")
public class HktsDictionaryListController {
    private final Logger logger = LoggerFactory.getLogger(HktsDictionaryListController.class);

    @Autowired
    public IHktsDictionaryListService iHktsDictionaryListService;

    /**
     * 分页查询数据
     *
     * @param page               分页信息
     * @param hktsDictionaryList 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getHktsDictionaryListPageList")
    @ApiOperation(value = "字典分页查询")
    public Result<CustomPage<List<HktsDictionaryList>>> getHontUserList(Page<HktsDictionaryList> page, HktsDictionaryList hktsDictionaryList) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iHktsDictionaryListService.selectPage(page, hktsDictionaryList)));
    }

    /**
     * 保存和修改公用的
     *
     * @param hktsDictionaryList 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsDictionaryListSave")
    @ApiOperation(value = "字典保存/修改")
    public Result<Object> hktsDictionaryListSave(HktsDictionaryList hktsDictionaryList) {
        iHktsDictionaryListService.saveOrUpdate(hktsDictionaryList);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/hktsDictionaryListGetById")
    @ApiOperation(value = "根据id查询")
    public Result<HktsDictionaryList> hktsDictionaryListGetById(String id) {
        HktsDictionaryList byId = iHktsDictionaryListService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsDictionaryListDelete")
    @ApiOperation(value = "根据id删除")
    public Result<Object> hontUserDelete(String id) {
        iHktsDictionaryListService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hktsDictionaryListBatchDelete")
    @ApiOperation(value = "根据id批量删除")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iHktsDictionaryListService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }
    /**
     * 根据key获取对应的数据
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/hktsDictionaryListGetByKey")
    @ApiOperation(value = "根据id查询")
    public Result<DictionaryVo> hktsDictionaryListGetByKey(String key) {
        DictionaryVo byId = iHktsDictionaryListService.hktsDictionaryListGetByKey(key);
        return ResultUtil.data(byId);
    }

    /**
     *
     *字典状态修改
     *
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/updateDictionaryListStatus")
    @ApiOperation(value = "根据id修改")
    public Result<Object> updateDictionaryListStatus(DictionaryParamterVo vo) {
        HktsDictionaryList byId = iHktsDictionaryListService.getById(vo.getId());
        byId=vo.getHktsDictionaryList(vo,byId);
        iHktsDictionaryListService.saveOrUpdate(byId);
        return ResultUtil.success("修改成功");
    }
}
